home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / tiff / libtiff / tif_compress.c < prev    next >
C/C++ Source or Header  |  1992-02-10  |  6KB  |  233 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_compress.c,v 1.26 92/02/10 19:06:13 sam Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler
  7.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  8.  *
  9.  * Permission to use, copy, modify, distribute, and sell this software and 
  10.  * its documentation for any purpose is hereby granted without fee, provided
  11.  * that (i) the above copyright notices and this permission notice appear in
  12.  * all copies of the software and related documentation, and (ii) the names of
  13.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  14.  * publicity relating to the software without the specific, prior written
  15.  * permission of Sam Leffler and Silicon Graphics.
  16.  * 
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  18.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  19.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  20.  * 
  21.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  22.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  23.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  24.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  25.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  26.  * OF THIS SOFTWARE.
  27.  */
  28.  
  29. /*
  30.  * TIFF Library
  31.  *
  32.  * Compression Scheme Configuration Support.
  33.  */
  34. #include "tiffioP.h"
  35.  
  36. #if USE_PROTOTYPES
  37. extern    int TIFFInitDumpMode(TIFF*);
  38. #ifdef PACKBITS_SUPPORT
  39. extern    int TIFFInitPackBits(TIFF*);
  40. #endif
  41. #ifdef CCITT_SUPPORT
  42. extern    int TIFFInitCCITTRLE(TIFF*), TIFFInitCCITTRLEW(TIFF*);
  43. extern    int TIFFInitCCITTFax3(TIFF*), TIFFInitCCITTFax4(TIFF*);
  44. #endif
  45. #ifdef THUNDER_SUPPORT
  46. extern    int TIFFInitThunderScan(TIFF*);
  47. #endif
  48. #ifdef NEXT_SUPPORT
  49. extern    int TIFFInitNeXT(TIFF*);
  50. #endif
  51. #ifdef LZW_SUPPORT
  52. extern    int TIFFInitLZW(TIFF*);
  53. #endif
  54. #ifdef JPEG_SUPPORT
  55. extern    int TIFFInitJPEG(TIFF*);
  56. #endif
  57. #else
  58. extern    int TIFFInitDumpMode();
  59. #ifdef PACKBITS_SUPPORT
  60. extern    int TIFFInitPackBits();
  61. #endif
  62. #ifdef CCITT_SUPPORT
  63. extern    int TIFFInitCCITTRLE(), TIFFInitCCITTRLEW();
  64. extern    int TIFFInitCCITTFax3(), TIFFInitCCITTFax4();
  65. #endif
  66. #ifdef THUNDER_SUPPORT
  67. extern    int TIFFInitThunderScan();
  68. #endif
  69. #ifdef NEXT_SUPPORT
  70. extern    int TIFFInitNeXT();
  71. #endif
  72. #ifdef LZW_SUPPORT
  73. extern    int TIFFInitLZW();
  74. #endif
  75. #ifdef JPEG_SUPPORT
  76. extern    int TIFFInitJPEG();
  77. #endif
  78. #endif
  79.  
  80. struct cscheme {
  81.     char*    name;
  82.     int    scheme;
  83.     int    (*init)();
  84. };
  85. static const struct cscheme CompressionSchemes[] = {
  86.     { "Null",        COMPRESSION_NONE,    TIFFInitDumpMode },
  87. #ifdef LZW_SUPPORT
  88.     { "LZW",        COMPRESSION_LZW,    TIFFInitLZW },
  89. #endif
  90. #ifdef PACKBITS_SUPPORT
  91.     { "PackBits",    COMPRESSION_PACKBITS,    TIFFInitPackBits },
  92. #endif
  93. #ifdef THUNDER_SUPPORT
  94.     { "ThunderScan",    COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
  95. #endif
  96. #ifdef NEXT_SUPPORT
  97.     { "NeXT",        COMPRESSION_NEXT,    TIFFInitNeXT },
  98. #endif
  99. #ifdef JPEG_SUPPORT
  100.     { "JPEG",        COMPRESSION_JPEG,    TIFFInitJPEG },
  101. #endif
  102. #ifdef CCITT_SUPPORT
  103.     { "CCITT RLE",    COMPRESSION_CCITTRLE,    TIFFInitCCITTRLE },
  104.     { "CCITT RLE/W",    COMPRESSION_CCITTRLEW,    TIFFInitCCITTRLEW },
  105.     { "CCITT Group3",    COMPRESSION_CCITTFAX3,    TIFFInitCCITTFax3 },
  106.     { "CCITT Group4",    COMPRESSION_CCITTFAX4,    TIFFInitCCITTFax4 },
  107. #endif
  108. };
  109. #define    NSCHEMES (sizeof (CompressionSchemes) / sizeof (CompressionSchemes[0]))
  110.  
  111. static struct cscheme const *
  112. findScheme(scheme)
  113.     int scheme;
  114. {
  115.     register struct cscheme const *c;
  116.  
  117.     for (c = CompressionSchemes; c < &CompressionSchemes[NSCHEMES]; c++)
  118.         if (c->scheme == scheme)
  119.             return (c);
  120.     return ((struct cscheme const *)0);
  121. }
  122.  
  123. static int
  124. TIFFNoEncode(tif, method)
  125.     TIFF *tif;
  126.     char *method;
  127. {
  128.     struct cscheme const *c = findScheme(tif->tif_dir.td_compression);
  129.     TIFFError(tif->tif_name,
  130.         "%s %s encoding is not implemented", c->name, method);
  131.     return (-1);
  132. }
  133.  
  134. int
  135. TIFFNoRowEncode(tif, pp, cc, s)
  136.     TIFF *tif;
  137.     u_char *pp;
  138.     int cc;
  139.     u_int s;
  140. {
  141.     return (TIFFNoEncode(tif, "scanline"));
  142. }
  143.  
  144. int
  145. TIFFNoStripEncode(tif, pp, cc, s)
  146.     TIFF *tif;
  147.     u_char *pp;
  148.     int cc;
  149.     u_int s;
  150. {
  151.     return (TIFFNoEncode(tif, "strip"));
  152. }
  153.  
  154. int
  155. TIFFNoTileEncode(tif, pp, cc, s)
  156.     TIFF *tif;
  157.     u_char *pp;
  158.     int cc;
  159.     u_int s;
  160. {
  161.     return (TIFFNoEncode(tif, "tile"));
  162. }
  163.  
  164. int
  165. TIFFNoDecode(tif, method)
  166.     TIFF *tif;
  167.     char *method;
  168. {
  169.     struct cscheme const *c = findScheme(tif->tif_dir.td_compression);
  170.     TIFFError(tif->tif_name,
  171.         "%s %s decoding is not implemented", c->name, method);
  172.     return (-1);
  173. }
  174.  
  175. int
  176. TIFFNoRowDecode(tif, pp, cc, s)
  177.     TIFF *tif;
  178.     u_char *pp;
  179.     int cc;
  180.     u_int s;
  181. {
  182.     return (TIFFNoDecode(tif, "scanline"));
  183. }
  184.  
  185. int
  186. TIFFNoStripDecode(tif, pp, cc, s)
  187.     TIFF *tif;
  188.     u_char *pp;
  189.     int cc;
  190.     u_int s;
  191. {
  192.     return (TIFFNoDecode(tif, "strip"));
  193. }
  194.  
  195. int
  196. TIFFNoTileDecode(tif, pp, cc, s)
  197.     TIFF *tif;
  198.     u_char *pp;
  199.     int cc;
  200.     u_int s;
  201. {
  202.     return (TIFFNoDecode(tif, "tile"));
  203. }
  204.  
  205. TIFFSetCompressionScheme(tif, scheme)
  206.     TIFF *tif;
  207.     int scheme;
  208. {
  209.     struct cscheme const *c = findScheme(scheme);
  210.  
  211.     if (!c) {
  212.         TIFFError(tif->tif_name,
  213.             "Unknown data compression algorithm %u (0x%x)",
  214.             scheme, scheme);
  215.         return (0);
  216.     }
  217.     tif->tif_predecode = NULL;
  218.     tif->tif_decoderow = TIFFNoRowDecode;
  219.     tif->tif_decodestrip = TIFFNoStripDecode;
  220.     tif->tif_decodetile = TIFFNoTileDecode;
  221.     tif->tif_preencode = NULL;
  222.     tif->tif_postencode = NULL;
  223.     tif->tif_encoderow = TIFFNoRowEncode;
  224.     tif->tif_encodestrip = TIFFNoStripEncode;
  225.     tif->tif_encodetile = TIFFNoTileEncode;
  226.     tif->tif_close = NULL;
  227.     tif->tif_seek = NULL;
  228.     tif->tif_cleanup = NULL;
  229.     tif->tif_flags &= ~TIFF_NOBITREV;
  230.     tif->tif_options = 0;
  231.     return ((*c->init)(tif));
  232. }
  233.